Skip to main content

โ˜๏ธ Running a function in the cloud

requirements
  • Being logged in
  • Being in the directory of the function
  • Enough quota

Deployโ€‹

First, the function needs to be deployed with the following command

gccli fx deploy
$ gccli fx deploy
๐Ÿ‘ท Verifying configuration...
๐Ÿ“ฆ๏ธ Archs: AMD64,ARM64,ARM
๐Ÿ”ฉ Building container image...
โณ๏ธ Process may take a while, please wait...
๐Ÿงฉ Compiling multi-arch image [OK]
๐Ÿšš Pushing image to registry...
๐Ÿ”ฅ Function successfully uploaded!
$ โ–ˆ

Run via public endpointโ€‹

The function needs a public endpoint to be called remotely with the following command

gccli fx public
$ gccli fx public
๐Ÿ‘ท Validating inputs...
๐Ÿšจ You must keep the public endpoint safe!
๐Ÿ”— Any existing endpoint will be revoked
โœ‹ Do you accept conditions? (y/n) โ†’ y
๐Ÿค– Public endpoint created successfully!
๐Ÿ”— https://api.greencloud.dev/gc/d322e8a50390418e83f15daa2bea32fb
$ โ–ˆ

Navigating to the link will get the dispatcher to queue the function to be run and will return a task ID.

https://api.greencloud.dev/gc/d322e8a50390418e83f15daa2bea32fb
โณ Your function is queued up and will be executed in due time.

The result will be available for the next 5 minutes at the link below..

https://api.greencloud.dev/gc/6408becf1815ce1e1d877349/result

You may now navigate to https://api.greencloud.dev/gc/[taskId]/result to get the result of the function. If the function run hasn't been completed yet, you will get a 404 response. You may need to poll the link multiple times until you get the response.

https://api.greencloud.dev/gc/6408becf1815ce1e1d877349/result
Hello from GO by GreenCloud!

Run via CLIโ€‹

You may also invoke the function from the CLI with the following command gccli fx invoke. You will be asked to provide an optional payload. This will give you a task ID that you can later use to get the response of this function.

$ gccli fx invoke
๐Ÿ‘ท Validating inputs...
๐Ÿ“„ Obtaining local information...
โŒš Timeout โ†’ 10
๐Ÿ“„ Payload โ†’ Hello from GreenCloud!
๐Ÿš€ Invoking function...
๐Ÿ“Œ ID: 6408a30b1815ce1e1d87731a
๐Ÿ“ป Waiting for task to output...
๐Ÿงพ 200 โ†’ Hello from GreenCloud!
$ โ–ˆ

Get function resultโ€‹

We may look up the result of a previously run function by the ID that was given during the invocation. Let's use the ID from the previous example to get the result of the function once again with the command gccli fx result . Enter the task ID when prompted.

$ gccli fx result
๐Ÿ‘ท Validating inputs...
๐Ÿ”– ID โ†’ 6408a30b1815ce1e1d87731a
๐Ÿ“ป Waiting for task to output...
๐Ÿงพ 200 โ†’ Hello from GreenCloud!
$ โ–ˆ